#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <unistd.h>

struct timeval start;
struct timeval end;

double time_diff(struct timeval *start, struct timeval *end){
    return (end->tv_sec - start->tv_sec) + 1e-6*(end->tv_usec - start->tv_usec);
}

void get_gmtime(char gmt_str[32])
{
    struct timeval tv;    
    struct tm* st;
    gettimeofday(&tv, NULL);    
    
/*    printf("%ld.%06ld\n", tv.tv_sec, tv.tv_usec);*/
    
    st=gmtime(&tv.tv_sec);
    
/*    printf("%4d-%02d-%02d %02d:%02d:%06.3f\n",st->tm_year+1900, st->tm_mon, st->tm_mday, st->tm_hour,st->tm_min,st->tm_sec+tv.tv_usec*1e-6);*/
    sprintf(gmt_str, "%4d-%02d-%02d %02d:%02d:%06.3f",st->tm_year+1900, st->tm_mon, st->tm_mday, st->tm_hour,st->tm_min,st->tm_sec+tv.tv_usec*1e-6);
/*    printf("usec = %d\n", tv.tv_usec);*/
}

int main(){
/*    time_t tt = time(NULL);*/
/*    printf("%s : \b%s\n", ctime(&tt), "xxx");*/


/*    char str[26];*/
/*    sprintf(str,"%s", ctime(&tt));*/

/*    printf("%s : xxx\n", str);*/

/*    str[24] = 0;*/
/*    str[25] = 0; */
/*    printf("%s : yyy \n", str);*/

    char gmt_str[32];
    get_gmtime(gmt_str);

    printf("%s\n", gmt_str);

    return 0;
}
